package org.devgframwork.datasync.core.support.parser.impl;


import org.devgframwork.datasync.core.support.parser.HandleParser;
import org.devgframwork.datasync.core.utils.SearchUtil;

import java.util.HashMap;
import java.util.Map;

public class SqlDefaultParser implements HandleParser {

  private String sql;

  private Map<String, ?> paramMap;

  public SqlDefaultParser(String sql, Map<String, ?> paramMap) {
    this.sql = sql;
    this.paramMap = paramMap;
  }

  @Override
  public String getText() {
    if (null == paramMap || paramMap.isEmpty()) {
      paramMap = new HashMap<>();
    }
    for (String key : paramMap.keySet()) {
      String value = SearchUtil.mapToString(paramMap, key);
      sql = SearchUtil.getSqlByParam(sql, key, value);
    }
    return SearchUtil.removeEmptyValue(sql);
  }


}
